import Vue from 'vue'
import App from './App'

// import {myRequest} from 'util/api.js' 
// Vue.prototype.$myRequest = myRequest

// var  urlslist= require('util/urlsList.js');
// Vue.prototype.$urlslist = urlslist.default.urls;

//加载系统配置文件
var _appconfig = require('@/appconfig.js').default;
var _applog = require('@/core/fwlog.js').default;
var _apptool = require('@/core/fwtool.js').default;
var _appauth = require('@/core/fwauthority.js').default;
var appmd5 = require('@/core/fwmd5.js');
var _appsign = require('@/core/fwsign.js').default;
var _appwechat = require('@/core/fwwechat.js').default;
var _apputil = require('@/core/fwutil.js').default;

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
	created() {
		if(!_appconfig.release){
			this._virtualLogin();
		}
	},
	methods: {
		//基础请求
		_post(api, params, method, successcallback, failcallback, completecallback) {
			
			//==============公用参数 开始====================
			//(固定参数)
			params.caPlatform = _appconfig.fwplatform;
			params.caDevice = _appconfig.fwdevice;
			params.caVersion = _appconfig.fwversion;
			//(用户身份参数)
			let authInfo = _appauth.getAuthInfo();
			if (authInfo) {
				params.caUserId = authInfo.userId;
				params.caUserToken = authInfo.userToken;
			}
			//==============公用参数 结束====================
			//组建API地址
			let requestAPI = _appconfig.fwrootapi + api;
			//请求签名
			params.caRndstr = _appsign.createRndStr(32);
			params.caRndnum = _appsign.createRndNum(32);
			params.caTimestamp = _apptool.timestamp();
			params.caSign = _appsign.makeSign(params, _appconfig.keysecret);

			_apptool.requestApi(requestAPI, params, method, successcallback, function() {
				_apptool.showModalInfo('网络异常！');
				failcallback && failcallback();
			}, completecallback);
		},

		// 检测登录
		_checkLogin(refresh) {
			let loginStatus = _appauth.checkAuth();
			if (!loginStatus) {
				_apptool.showToastInfo('请登录后再操作！', null, 1000, function(res) {
					//如果需要回调，则必须在当前面实现refreshPage()方法
					uni.navigateTo({
						url: '/pages/basic/login?refresh=' + (refresh ? '2' : '1'),
					});
				});
			}
			return loginStatus;
		},

		// 模拟帐号
		_virtualLogin() {
			if ((!_appconfig.release) && (_appconfig.testData.testUserId > 0)) {
				//身份数据缓存到本地
				_appauth.setUserCacheData({
					user_id: _appconfig.testData.testUserId,
					user_token: _appconfig.testData.testUserToken,
					nickname: '模拟帐号',
					avatar: '/pages/res/owner/icon_owner_portrait.png',
					mobile: '1000000000'
				});
			}
		},
		// APP提示
		_showToast(msg, mask, duration, successcallback, failcallback, completecallback){
			_apptool.showToastInfo(msg, mask, duration, successcallback, failcallback, completecallback);
		},
		
		//变量
		_appconfig(){
			return _appconfig;
		},
		_applog(){
			return _applog;
		},
		_apptool(){
			return _apptool;
		},
		_appauth(){
			return _appauth;
		},
		_appsign(){
			return _appsign;
		},
		_appwechat(){
			return _appwechat;
		},
		_apputil(){
			return _apputil;
		}
	}
}) 
app.$mount()
